using System;
using System.Collections.Generic;
using Volo.Abp.Application.Dtos;
using TenantManagementService.Monitoring;

namespace TenantManagementService.Monitoring
{
    /// <summary>
    /// 告警规则DTO
    /// </summary>
    public class AlertRuleDto : EntityDto<Guid>
    {
        /// <summary>
        /// 租户ID
        /// </summary>
        public Guid? TenantId { get; set; }

        /// <summary>
        /// 规则名称
        /// </summary>
        public string Name { get; set; } = string.Empty;

        /// <summary>
        /// 规则显示名称
        /// </summary>
        public string DisplayName { get; set; } = string.Empty;

        /// <summary>
        /// 规则描述
        /// </summary>
        public string? Description { get; set; }

        /// <summary>
        /// 监控指标名称
        /// </summary>
        public string MetricName { get; set; } = string.Empty;

        /// <summary>
        /// 告警级别
        /// </summary>
        public AlertLevel Level { get; set; }

        /// <summary>
        /// 比较操作符
        /// </summary>
        public string Operator { get; set; } = string.Empty;

        /// <summary>
        /// 阈值
        /// </summary>
        public decimal Threshold { get; set; }

        /// <summary>
        /// 持续时间（秒）
        /// </summary>
        public int Duration { get; set; }

        /// <summary>
        /// 评估间隔（秒）
        /// </summary>
        public int EvaluationInterval { get; set; }

        /// <summary>
        /// 是否启用
        /// </summary>
        public bool IsEnabled { get; set; }

        /// <summary>
        /// 标签过滤器
        /// </summary>
        public Dictionary<string, string>? LabelFilters { get; set; }

        /// <summary>
        /// 通知渠道
        /// </summary>
        public List<string>? NotificationChannels { get; set; }

        /// <summary>
        /// 规则表达式
        /// </summary>
        public string? Expression { get; set; }

        /// <summary>
        /// 最后触发时间
        /// </summary>
        public DateTime? LastTriggeredTime { get; set; }

        /// <summary>
        /// 触发次数
        /// </summary>
        public int TriggerCount { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreationTime { get; set; }

        /// <summary>
        /// 最后修改时间
        /// </summary>
        public DateTime? LastModificationTime { get; set; }

        /// <summary>
        /// 告警级别文本
        /// </summary>
        public string LevelText => Level switch
        {
            AlertLevel.Info => "信息",
            AlertLevel.Warning => "警告",
            AlertLevel.Critical => "严重",
            AlertLevel.Emergency => "紧急",
            _ => "未知"
        };

        /// <summary>
        /// 操作符文本
        /// </summary>
        public string OperatorText => Operator.ToLower() switch
        {
            "gt" => "大于",
            "gte" => "大于等于",
            "lt" => "小于",
            "lte" => "小于等于",
            "eq" => "等于",
            "ne" => "不等于",
            _ => Operator
        };
    }
}